using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FernUniHagen.CompilerExtension.DataStructures;
using FernUniHagen.CompilerExtension.Interfaces;
using Roslyn.Compilers.Common;
using Roslyn.Compilers.CSharp;
using Roslyn.Services;

namespace FernUniHagen.CompilerExtension.Adaptor
{
    public class IdentifierSyntaxAdapter : BlockNodeFactory, IMultiplicityConvertible<CommonSyntaxNode>, IReferencable
    {
        #region Fields
        IdentifierNameSyntax _identifier;
        IDocument _doc;
        BlockSyntax _block;
        StatementSyntax _stmt;
        #endregion

        #region constructors
        private IdentifierSyntaxAdapter()
        { }

        public IdentifierSyntaxAdapter(IdentifierNameSyntax node)
        {
            _identifier = node;
        }

        public IdentifierSyntaxAdapter(IDocument doc, BlockSyntax block, IdentifierNameSyntax identifier, StatementSyntax stmt) : this(identifier)
        {
            _doc = doc;
            _block = block;
            _stmt = stmt;

        }
        #endregion

        
        public override StatementReplacement<CommonSyntaxNode> ConvertToMutiplicity(string newVariableName)
        {
            
            var newIdentifier = Syntax.ParseExpression(newVariableName);
            return new StatementReplacement<CommonSyntaxNode>(_identifier, newIdentifier);
        }

        public SyntaxNodeInfo GetReference()
        {
            SyntaxNodeInfo nodeInfo = new SyntaxNodeInfo(_doc, _block, _identifier, _stmt, _identifier);
            return nodeInfo;
        }
    }
}
